//
//  YUNViewController.m
//  BaiSi
//
//  Created by warm on 17/7/30.
//  Copyright © 2017年 hp. All rights reserved.
//

#import "YUNViewController.h"
#import "YUNNewViewController.h"
#import "YUNEssenceViewController.h"
#import "YUNMeTableViewController.h"
#import "YUNPublishViewController.h"
#import "YUNFriendTrendViewController.h"
#import "UIImage+image.h"

#import "YUNTabBar.h"
#import "YUNNavControl.h"

@interface YUNViewController ()

@end

@implementation YUNViewController
+(void)load
{

    UITabBarItem *item=[UITabBarItem appearanceWhenContainedIn:self, nil];
    

    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:attrs forState:UIControlStateSelected];
    
    // 设置字体尺寸:只有设置正常状态下,才会有效果
    NSMutableDictionary *attrsNor = [NSMutableDictionary dictionary];
    attrsNor[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:attrsNor forState:UIControlStateNormal];

}


-(void)viewWillAppear:(BOOL)animated
{


    [super viewWillAppear:animated];
    
    NSLog(@"%@",self.tabBar.subviews);


}

-(void)setUpTabBar
{

    YUNTabBar *tabBar=[[YUNTabBar alloc]init];

    
    [self setValue:tabBar forKey:@"tabBar"];

}







- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    [self setUpAllChildViewController];
    [self setupAllTitleButton];
    
    [self setUpTabBar];
    
    
}

-(void)setUpAllChildViewController
{

    
    YUNEssenceViewController *essenceVc=[[YUNEssenceViewController alloc]init];
    
    YUNNavControl *nav=[[YUNNavControl alloc]initWithRootViewController:essenceVc];
    
    [self addChildViewController:nav];
    
    
    
    YUNNewViewController *newVc=[[YUNNewViewController alloc]init];
    
   YUNNavControl *nav1=[[YUNNavControl alloc]initWithRootViewController:newVc];
    [self addChildViewController:nav1];
    
    /*
    // 发布
    YUNPublishViewController *publishVc = [[YUNPublishViewController alloc] init];
    // tabBarVc:会把第0个子控制器的view添加去
    [self addChildViewController:publishVc];
     */
    
    // 关注
    YUNFriendTrendViewController *ftVc = [[YUNFriendTrendViewController alloc] init];
    YUNNavControl *nav3 = [[YUNNavControl alloc] initWithRootViewController:ftVc];
    // initWithRootViewController:push
    
    // tabBarVc:会把第0个子控制器的view添加去
    [self addChildViewController:nav3];
    
    // 我
    YUNMeTableViewController *meVc = [[YUNMeTableViewController alloc] init];
   YUNNavControl *nav4 = [[YUNNavControl alloc] initWithRootViewController:meVc];
    // initWithRootViewController:push
    
    // tabBarVc:会把第0个子控制器的view添加去
    [self addChildViewController:nav4];
    
    



}

// 设置tabBar上所有按钮内容
- (void)setupAllTitleButton
{
    
    UINavigationController *nav=self.childViewControllers[0];
    
    // 0:nav
    nav.tabBarItem.title = @"精华";
    nav.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    // 快速生成一个没有渲染图片
   nav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_essence_click_icon"];
    
    //nav.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_essence_click_icon"];

  // [nav.tabBarItem.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
   // nav.tabBarItem.selectedImage=image;
    
    // 1:新帖
    
    UINavigationController *nav1=self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
     nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
    /*
    // 2:发布
    
    YUNPublishViewController *publishVc=self.childViewControllers[2];
    publishVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
      nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
     */
    // 3.关注
    
    UINavigationController *nav3=self.childViewControllers[2];
    nav3.tabBarItem.title = @"关注";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
       nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
    
    
    // 4.我
    
    UINavigationController *nav4=self.childViewControllers[3];
    nav4.tabBarItem.title = @"我";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
      nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
    
    
    
    
    
    
    
    

}
@end
